﻿using System.Web;
using DAL;
using Newtonsoft.Json;
using System.Web.SessionState;
using System.Text;

namespace AjaxLibrary
{
    class sysupgrade : IHttpHandler,IRequiresSessionState
    {
        #region IHttpHandler 成员

        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            string companyType=context.Request["companyType"];

            int totalCount = 0;
            double totalMoney = 0;

            if (companyType == "2")// 供应商
            {
                DAL.DeductMoney.getDeductHistoryList(logic.customer.getCompanyId(), out totalCount, out totalMoney);
            }
            SysUpgradeEntity entity = logic.sysUpgrade.queryRangeTip();

            using (JsonTextWriter jWriter = new JsonTextWriter(context.Response.Output))
            {
                jWriter.WriteStartObject();
                jWriter.WritePropertyName("title");
                jWriter.WriteValue(entity!=null?entity.Title:"");
                jWriter.WritePropertyName("description");

                if (totalCount != 0)
                {
                    StringBuilder noticeInfo = new StringBuilder("");
                    noticeInfo.AppendFormat("您最近三天有<font color='red'>{0}</font>笔扣款，扣款总金额：<font color='red'>￥{1:F2}</font>,", totalCount, totalMoney);
                    noticeInfo.AppendFormat("<br /><br /><A href='user_deductMoneyInfo.html' hidefocus='false' id='ommand'><FONT color='#ff0000'>点击查看详细</FONT></A>");

                    jWriter.WriteValue((entity!=null?entity.Description:"") + "<br /><br />" + noticeInfo.ToString());
                }
                else
                {
                    if (entity!=null)
                    {
                        jWriter.WriteValue(entity.Description);
                    }
                }
                jWriter.WriteEndObject();
            }
        }

        #endregion
    }
}